'use strict'

// //Md5
// let crypto = require('crypto');
// let hash = crypto.createHash('md5');
// //多次调用hash
// hash.update('wdnmd');
// hash.update('adc')
// //打印
// console.log(hash.digest("hex"));


// RSA非对称加密

let crypto = require('crypto');
let fs = require('fs');

function loadKey(file){
    return fs.readFileSync(file,"utf-8")
}

let prvKey = loadKey('./PrvKey.txt');
let puKey = loadKey('./PuKey.txt');

let show  = '唯独你没懂'; 

//私钥加密
let enc_prv = crypto.privateEncrypt(prvKey,Buffer.from(show,'utf-8'));
console.log(enc_prv.toString('hex'));

//公钥解密
let dec_pub = crypto.publicDecrypt(puKey,enc_prv);
console.log(dec_pub.toString("utf-8"));

let show2 = '不会吧，不会吧！！！'
//公钥加密
let enc_pub = crypto.publicEncrypt(puKey,Buffer.from(show2,'utf-8'));
console.log(enc_pub.toString('hex'));
//私钥解密
let dec_prv = crypto.privateDecrypt(prvKey,enc_pub);
console.log(dec_prv.toString('utf-8'));